//#region js跳转页面
let spBili = document.getElementById('spBili');

// 元素.addEventListener表示给元素添加事件监听
// 参数1是要监听的事件类型，参数2是事件发生时要执行代码
// click是点击事件
spBili.addEventListener('click', () => {
  // location.href表示跳转到指定页面
  location.href = 'https://bilibili.com';
});

let spDelay = document.getElementById('spDelay');

spDelay.addEventListener('click', () => {
  // 单次的延迟执行
  setTimeout(() => {
    // 新窗口中打开链接
    window.open('https://bilibili.com')
    // location.href = 'https://bilibili.com';
  }, 2000);
});

//#endregion

//#region 倒计时页面跳转
let spPage = document.getElementById('spPage');
let spInfo = document.getElementById('spInfo');

let count = 5;

spPage.addEventListener('click', () => {
  spInfo.innerHTML = `还有${count}秒跳转到B站`;

  setInterval(() => {
    count--;
    if (count == 0) {
      location.href = 'https://bilibili.com';
      return;
    }
    spInfo.innerHTML = `还有${count}秒跳转到B站`;
  }, 1000);
});

//#endregion
